home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / components / commandlinehandler.py next >
Encoding:
Python Source  |  2007-11-12  |  3.4 KB  |  78 lines

  1. # Miro - an RSS based video player application
  2. # Copyright (C) 2005-2007 Participatory Culture Foundation
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  17.  
  18. """Democracy Command Line Handler."""
  19.  
  20. from xpcom import components
  21.  
  22. class DemocracyCLH:
  23.     _com_interfaces_ = [components.interfaces.nsICommandLineHandler]
  24.     _reg_clsid_ = "{951DF9BD-EED3-4571-8A87-A16BA157A6CD}"
  25.     _reg_contractid_ = "@participatoryculture.org/dtv/commandlinehandler;1"
  26.     _reg_desc_ = "Democracy Command line Handler"
  27.  
  28.     def __init__(self):
  29.         pass
  30.  
  31.     def handle(self, commandLine):
  32.         args = [commandLine.getArgument(i) for i in range(commandLine.length)]
  33.         if "--register-xul-only" in args:
  34.             return
  35.  
  36.         chromeURL = "chrome://dtv/content/main.xul"
  37.         windowName = "DemocracyPlayer"
  38.         wwatch = components.classes["@mozilla.org/embedcomp/window-watcher;1"]\
  39.                 .getService(components.interfaces.nsIWindowWatcher)
  40.         pybridgeCID = "@participatoryculture.org/dtv/pybridge;1"
  41.         pybridge = components.classes[pybridgeCID]. \
  42.                     getService(components.interfaces.pcfIDTVPyBridge)
  43.         startupError = pybridge.getStartupError()
  44.         if startupError:
  45.             startupErrorURL = "chrome://dtv/content/startuperror.xul"
  46.             wwatch.openWindow(None, startupErrorURL, "DemocracyPlayerError", 
  47.                     "chrome,dialog=yes,all", None)
  48.             return
  49.  
  50.         pybridge.createProxyObjects()
  51.         pybridge.handleCommandLine(commandLine)
  52.  
  53.         existingWindow = wwatch.getWindowByName(windowName, None)
  54.         if existingWindow is None:
  55.             try:
  56.                 pybridge.deleteVLCCache()
  57.             except:
  58.                 print "WARNING: error in deleteVLCCache()"
  59.             if pybridge.getStartupTasksDone():
  60.                 wwatch.openWindow(None, chromeURL, windowName,
  61.                         "chrome,resizable,dialog=no,all", None)
  62.             else:
  63.                 jsbridgeCID = "@participatoryculture.org/dtv/jsbridge;1"
  64.                 jsbridge = components.classes[jsbridgeCID]. \
  65.                         getService(components.interfaces.pcfIDTVJSBridge)
  66.                 jsbridge.performStartupTasks()
  67.                 return
  68.         else:
  69.             # If Democracy is already running and minimize, make the
  70.             # tray icon disappear
  71.             minimizer = components.classes["@participatoryculture.org/dtv/minimize;1"].getService(components.interfaces.pcfIDTVMinimize)
  72.             minimizer.restoreAll()
  73.  
  74. catman = components.classes["@mozilla.org/categorymanager;1"].getService()
  75. catman.queryInterface(components.interfaces.nsICategoryManager)
  76. catman.addCategoryEntry("command-line-handler", "z-default",
  77.         "@participatoryculture.org/dtv/commandlinehandler;1", True, True)
  78.